package com.example.queryexpressdelivery_01.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.queryexpressdelivery_01.R;

import java.util.List;
import java.util.Map;

public class IndexRvAdapter extends RecyclerView.Adapter<IndexRvAdapter.ViewHolder>{
    private List<Map<String,String>> expressInfo;
    public void setExpressList(List<Map<String,String>> expressInfo) {
        this.expressInfo = expressInfo;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_main_index,parent,false);
        ViewHolder viewHolder = new ViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Map<String, String> map = expressInfo.get(position);
        for (Map.Entry<String, String> entry : map.entrySet()) {
            holder.tvItemRVKey.setText(entry.getKey());
            holder.tvItemRVValue.setText(entry.getValue());
            break;
        }
    }

    @Override
    public int getItemCount() {
        return expressInfo.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        TextView tvItemRVKey;
        TextView tvItemRVValue;
        public ViewHolder(@NonNull View itemView){
            super(itemView);
            tvItemRVKey = itemView.findViewById(R.id.tvItemRVKey);
            tvItemRVValue = itemView.findViewById(R.id.tvItemRVValue);
        }
    }
}
